<template>
	<view class="setting-popup-content">
		<view class="title-row">
			<text style="color: #a3aab4;" @click="close(false)">关闭</text>
			<text>默认设置</text>
			<text style="color: #3571fb;" @click="confirm">确认</text>
		</view>
		<view class="msg-row input-row">
			<view class="left">
				<iconfont :name="'type'" :size="25"></iconfont>
				<text>{{obj.name}}</text>
			</view>
			<view class="right">
				<image :src="obj.imgSrc" style="height: 150rpx;" mode="heightFix">
				</image>
			</view>
		</view>
		<view class="msg-row other-row">
			<view class="row-item">
				<view class="left">
					<uni-icons type="calendar" size="25"></uni-icons>
					<text>保质期</text>
				</view>
				<view class="right">
					<my-number-box :background="'#fff'" :value="obj.warrantTime" :min="1" :max="999"
						@change="changeDay" />
					<view class="unit-box">
						<text>天</text>
					</view>
				</view>
			</view>
			<view class="row-item">
				<view class="left">
					<iconfont :name="'location'" :size="25"></iconfont>
					<text>位置</text>
				</view>
				<view class="right">
					<uni-data-picker ref="picker" placeholder="请选择放置的位置" popup-title="请选择放置的位置" :localdata="dataTree"
						:modelValue="obj.location" :clearIcon="false" @change="onchange" @popupopened="popupopened"
						@popupclosed="popupclosed">
					</uni-data-picker>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-personal-obj-setting-pop",
		props: {
			dataTree: {},
			obj: {}
		},
		data() {
			return {

			};
		},
		methods: {

			// 请求
			confirm() {
				this.obj.location = this.obj.location == '1-1' ? this.dataTree[0].text + "-" + this
					.dataTree[0]
					.children[0].text : this.obj.location[0].text + "-" + this.obj
					.location[1].text
				uni.$api.object.updatePersonalObjSetting(this.obj)
				this.close(true)
			},

			// 事件处理
			close(flag) {
				this.$emit('close', flag)
			},
			// 保质期
			changeDay(value) {
				this.obj.warrantTime = value
			},
			// 位置
			onchange(e) {
				this.obj.location = e.detail.value
			},
			// 处理双层弹窗的遮罩层响应问题
			popupopened(e) {
				this.$emit('popupopened')
			},
			popupclosed(e) {
				this.$emit('popupclosed')
			},
		}
	}
</script>

<style lang="scss">
	.setting-popup-content {
		border-radius: 20rpx 20rpx 0 0;
		background-color: #e5e6eb;
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.title-row {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 22px;
			width: 98%;
		}

		.msg-row {
			background-color: #fff;
			border-radius: 12rpx;
			display: flex;
			justify-content: space-between;
			width: 86%;
			padding: 0 6%;
			font-size: 20px;
			align-items: center;
			margin-top: 20rpx;

			.left {
				>text {
					margin-left: 15rpx;
				}
			}
		}

		.other-row {
			display: flex;
			flex-direction: column;

			.row-item {
				width: 100%;
				display: flex;
				justify-content: space-between;
				margin: 20rpx;
				align-items: center;

				.right {
					display: flex;
					align-items: center;
				}
			}
		}
	}
</style>
